<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div></div>
    <button>清除</button>
    <button>恢复</button>
    <script>
        var div=document.querySelector('div');
        var button=document.querySelectorAll('button');
        function formatDate(time){
            var nowTime=new Date();
            var year=nowTime.getFullYear();
            var month=nowTime.getMonth()+1;
            var m= month<10?'0'+month:month;
            var dates=nowTime.getDate();
            dates=dates<10?'0'+dates:dates;
            var day=nowTime.getDay();
            var arr=['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
            var d=arr[day];
            var h=nowTime.getHours();
            h=h<10?'0'+h:h;
            var min=nowTime.getMinutes();
            min=min<10?'0'+min:min;
            var s=nowTime.getSeconds();
            s=s<10?'0'+s:s;
            return div.innerHTML=year+'年'+m+'月'+dates+'日'+h+':'+min+':'+s+d;

        }
        // console.log(formatDate());
        // formatDate();
        formatDate();
        var set= setInterval(formatDate,1000);
        // setInterval(function(){

        // },1000)
        button[0].addEventListener('click',fn);
        function fn(){
            clearInterval(set);
        }
        button[1].addEventListener('click',ff)
        function ff(){
            var set= setInterval(formatDate,1000);
        }
    </script>
</body>
</html>